﻿using System;
using EventLogAnalyzer.Common;
using EventLogAnalyzer.Model;

namespace EventLogAnalyzer.ViewModel
{
    public class EventLogViewModel : ViewModelBase
    {
        private readonly EventLog _model;
        public event ShowLogDetailsEventHandler ShowLogDetailsRequest;

        public EventLogViewModel(EventLog model)
        {
            _model = model;
        }

        public int CommonEventId
        {
            get { return _model.CommonEventId; }
        }

        public string Data
        {
            get { return _model.Data; }
        }

        public string EventTitle
        {
            get
            {
                var trimmedData = _model.Data.TrimStart(' ', '\n','\r','\t');
                return trimmedData.Substring(0, trimmedData.Length >= 400 ? 400 : trimmedData.Length);
            }
        }

         
        private bool _isToBeShown;
        public bool IsToBeShown
        {
            get { return _isToBeShown; }
            set
            {
                if (_isToBeShown != value)
                {
                    _isToBeShown = value;
                    OnPropertyChanged("IsToBeShown");
                }
            }
        }

        
        private RelayCommand _showEventDetailsCommand;
        public RelayCommand ShowEventDetailsCommand
        {
            get
            {
                if (_showEventDetailsCommand == null)
                {
                    _showEventDetailsCommand = new RelayCommand(param =>
                                                                {
                                                                    if(ShowLogDetailsRequest != null)
                                                                        ShowLogDetailsRequest(this, new ShowLogDetailsEventHandlerArgs(){Data = Data});
                                                                });
                }
                return _showEventDetailsCommand;

            }
        }

        public DateTime TimeStamp 
        { 
            get
            {
                return _model.TimeStamp;    
            }
        }

        
        private bool _shouldHighLight;
        public bool ShouldHighLight
        {
            get { return _shouldHighLight; }
            set
            {
                if (_shouldHighLight != value)
                {
                    _shouldHighLight = value;
                    OnPropertyChanged("ShouldHighLight");
                }
            }
        }

    }
}